{extend name="public/base" /}
{block name="style"}
<style>
    .table-bordered > tbody > tr > td {
        vertical-align: middle
    }

    .margin {
        margin: 2px 5px
    }
</style>
{/block}
{block name="title"}
<h1>用户管理</h1>
{/block}
{block name="content"}
<section class="content">
    <div class="row">
        <div class="col-md-12">
            <div class="box">
                <div class="box-body">
                    <form class="form-inline" name="searchForm" id="searchForm" action="" method="GET">
                        <div class="form-group">
                            <input type="text" value="{$queryCode ? $queryCode : '' ;}"
                                   name="queryCode" id="queryCode" class="form-control" placeholder="会员编号">
                        </div>
                        <div class="form-group">
                            <button class="btn btn-primary" type="submit"><i class="fa fa-search"></i> 查询
                            </button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
    <div class="row">
        <div class="col-md-12">
            <div class="box">
                <div class="box-header">
                    <a class="btn btn-primary btn-sm margin" href="{:url('user/add','id=')}">
                        +添加用户
                    </a>
                </div>
                <div class="box-body table-responsive">
                    <table id="dListTable" class="table table-hover table-bordered" width="100%">
                        <thead>
                        <tr>
                            <th width="3%"><input type="checkbox" class="checkbox" title="全选/取消"
                                                  onclick="doCheckAll(this, 'dListTable')"></th>
                            <th width="10%">用户账号</th>
                            <th width="10%">用户昵称</th>
                            <th width="10%">所属角色</th>
                            <th width="10%">手机</th>
                            <th width="10%">邮箱</th>
                            <th width="17%">创建时间</th>
                            <th width="10%">状态</th>
                            <th width="30%">操作</th>
                        </tr>
                        </thead>
                        <tbody>
                        {volist name="list" id="vo" empty="$empty"}
                        <tr>
                            <td><input type="checkbox" class="checkbox data-list-check" id="ckb_{$vo.user_id}"/></td>
                            <td>{$vo.user_account}</td>
                            <td>{$vo.user_name}</td>
                            <td>{$vo.role_name}</td>
                            <td>{$vo.user_phone}</td>
                            <td>{$vo.user_email}</td>
                            <td>{$vo.create_time}</td>
                            {if condition="($vo.user_status == 1)"}
                            <td style="color: #00e765;">{$vo.user_status_text}</td>
                            {/if}
                            {if condition="($vo.user_status == 0)"}
                            <td style="color: #ff2222;">{$vo.user_status_text}</td>
                            {/if}
                            <td>
                                <a href="{:url('user/edit','id='.$vo.user_id)}" class="btn btn-info btn-sm margin">
                                    <i class="fa fa-edit"></i>编辑
                                </a>
                                {if condition="($vo.user_status == 1) AND ($vo.user_account != 'admin')"}
                                <button onclick="doChangeStatus('{$vo.user_id}', 0)" class="btn btn-default btn-sm margin">
                                    <i class="fa fa-toggle-off"></i>禁用
                                </button>
                                {/if}
                                {if condition="($vo.user_status == 0) AND ($vo.user_account != 'admin')"}
                                <button onclick="doChangeStatus('{$vo.user_id}', 1)" class="btn btn-success btn-sm margin">
                                    <i class="fa fa-toggle-on"></i>启用
                                </button>
                                {/if}
                                {if condition="($vo.user_account != 'admin')"}
                                <button onclick="doDel('{$vo.user_id}')" class="btn btn-danger btn-sm margin">
                                    <i class="fa fa-close"></i>删除
                                </button>
                                {/if}
                            </td>
                        </tr>
                        {/volist}
                        </tbody>
                    </table>
                </div>
                <div class="box-footer">
                    <a class="btn btn-danger btn-sm margin" href="javascript:" onclick="doBatchDel()">
                        批量删除
                    </a>
                </div>
                <div class="box-footer" style="text-align: center;">
                    {$page}
                </div>
            </div>
        </div>
    </div>
</section>
{/block}
{block name="script"}
{load href="/static/common/js/common.js"}
{load href="/static/common/js/layer/layer.js"}
<script>
    var doDel = function (ids) {
        layer.confirm('确定要删除吗？',
            {
                btn: ['确定', '取消']
            },
            function () {
                location.href = "{:url('user/del')}" + "?id=" + ids;
            },
            function () {
            });
    };

    var doBatchDel = function () {
        var selected = $.trim(getCheckedList('dListTable'));
        if (selected === '' || selected === undefined) {
            layer.msg('请选择要删除的数据！', {icon: 2});
            return;
        }
        doDel(selected);
    };

    var doChangeStatus = function (id, status) {
        location.href = "{:url('user/changeStatus')}" + "?id=" + id + "&status=" + status;
    };
</script>
{/block}